# encoding:utf-8
import os
import json

def main():
    res = get_dir('./')
    with open('catalogue.json', 'w', encoding="utf-8") as json_file:
    		json.dump(res, json_file, ensure_ascii=False)
    # print(json.dumps(res, sort_keys=True,indent=2).encode('utf-8').decode('"unicode-escape'))

ignore_dirs = ['.git','.idea','style']
def get_dir(path):
    res = []
    for dir in os.listdir(path):
        if os.path.isdir(dir) and dir not in ignore_dirs:
            res.append({'tab_name':dir,'dir':dir,'children':get_dir(dir)})
        elif not os.path.isdir(dir) and os.path.splitext(dir)[-1]=='.md':
            res.append({'title':os.path.splitext(dir)[0],'url':dir})
    return res


if __name__ == '__main__':
	main()
